#ifndef TREEBPLUS_H_
#define TREEBPLUS_H_
#include "../Record.h"
#include "NodeInternal.h"
#include "NodeLeaf.h"
#include "../../Managers/BlockFileManager.h"

namespace Tree {

class TreeBPlus {

private:

	//TODO: search this in config.file
	static const unsigned int nodeMaxSize = 100;

	BlockFileManager* treeFile;
	Node* rootNode;

public:

	TreeBPlus();

	void addInTree(Record* recordToAdd);
	void removeInTree(string key);
	void exportToTxt(string name);

	virtual ~TreeBPlus();

protected:

	bool insertInNode(Node* node, RecordNode* recordNodeToAdd);
	bool removeInNode(Node* node, string key);
	void resolveOverflow(Node* nodeOverflowed, NodeInternal* parent);
	void resolveRootOverflow();
	void resolveUnderflow(Node* nodeUnderflowed, NodeInternal* parent);
	unsigned int saveNode(Node* nodeToSave);
	Node* createNode(unsigned int nodeID);
	void balanceNodes(Node* nodeOverflowed, Node* newBrother);


};

}

#endif /* TREEBPLUS_H_ */
